package com.leorui.schoollife.entity

import net.sf.json.JSONArray
import net.sf.json.JSONObject
import java.io.Serializable
import java.util.*

class SchoolAnnouncementResponse : Serializable {
    var status: Int? = null
    var msg: String? = null
    var announcementList: List<SchoolAnnouncementEntity?>? = null

    constructor() : this(null, null, null)
    constructor(status: Int?, msg: String?, announcementList: List<SchoolAnnouncementEntity?>?) {
        this.status = status
        this.msg = msg
        this.announcementList = announcementList
    }

    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["status"] = status
        json["msg"] = msg
        val announcementArray = JSONArray()
        announcementList?.forEach {
            announcementArray.add(it?.toMap())
        }
        json["announcement_list"] = announcementArray.toList()
        return json.toMap()
    }
}

class SchoolAnnouncementEntity : Serializable {
    var mainTitle: String? = null
    var contentList: List<ContentEntity?>? = null

    constructor() : this(null, null)
    constructor(mainTitle: String?, contentList: List<ContentEntity?>?) {
        this.mainTitle = mainTitle
        this.contentList = contentList
    }

    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["main_title"] = mainTitle
        val contentArray = JSONArray()
        contentList?.forEach {
            contentArray.add(it?.toMap())
        }
        json["content_list"] = contentArray.toList()
        return json.toMap()
    }
}

class ContentEntity : Serializable {
    var time: String? = null
    var content: String? = null
    var url: String? = null
    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["time"] = time
        json["content"] = content
        json["url"] = url
        return json.toMap()
    }
}

class SchoolAnnouncementDetailResponse : Serializable {
    var status: Int? = null
    var msg: String? = null
    var detailEntity: SchoolAnnouncementDetailEntity? = null

    constructor() : this(null, null, null)
    constructor(status: Int?, msg: String?, detailEntity: SchoolAnnouncementDetailEntity?) {
        this.status = status
        this.msg = msg
        this.detailEntity = detailEntity
    }

    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["status"] = status
        json["msg"] = msg
        json["detail_entity"] = detailEntity?.toMap()
        return json.toMap()
    }
}

class SchoolAnnouncementDetailEntity : Serializable {
    var title: String? = null
    var time: String? = null
    var author: String? = null
    var contentList: LinkedList<String?>? = null
    var imgList: LinkedList<String?>? = null
    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["title"] = title
        json["time"] = time
        json["author"] = author
        val contentListJsonArray = JSONArray()
        contentList?.forEach {
            contentListJsonArray.add(it)
        }
        json["content_list"] = contentListJsonArray.toList()


        val imgListJsonArray = JSONArray()
        imgList?.forEach {
            imgListJsonArray.add(it)
        }
        json["img_list"] = imgListJsonArray.toList()
        return json.toMap()
    }
}
